package com.qys.livesMall.shop.controller.app;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.app.user.model.entity.H2AppUser;
import com.qys.livesMall.app.user.model.entity.H2AppUserAddress;
import com.qys.livesMall.app.user.service.IH2AppUserAddressService;
import com.qys.livesMall.app.user.service.IH2AppUserService;
import com.qys.livesMall.app.user.utils.PasswordUtil;
import com.qys.livesMall.common.constants.Constants;
import com.qys.livesMall.common.exception.QysException;
import com.qys.livesMall.common.exception.enums.ExceptionEnum;
import com.qys.livesMall.common.message.MessageServer;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.common.utils.MessageUtils;
import com.qys.livesMall.common.utils.bean.BeanProUtils;
import com.qys.livesMall.finance.model.entity.shop.FinanceShopAccount;
import com.qys.livesMall.finance.service.FinanceShopAccountService;
import com.qys.livesMall.framework.utils.SecurityUtils;
import com.qys.livesMall.open.enums.PushMessageTypeEnum;
import com.qys.livesMall.open.modal.dto.app.PushUserDeviceContentDTO;
import com.qys.livesMall.open.modal.dto.mail.PushTitleDTO;
import com.qys.livesMall.open.modal.dto.mail.PushUserDeviceDTO;
import com.qys.livesMall.open.service.PushUserDeviceService;
import com.qys.livesMall.product.service.H2ProductSkuAttributeService;
import com.qys.livesMall.shop.constants.OrderStatus;
import com.qys.livesMall.shop.constants.PayStatus;
import com.qys.livesMall.shop.constants.ShopOrderMessageConstants;
import com.qys.livesMall.shop.dao.H2ShopBaseDao;
import com.qys.livesMall.shop.enums.ShopMessageEnum;
import com.qys.livesMall.shop.mapper.ShopOrderInfoMapper;
import com.qys.livesMall.shop.modal.dto.*;
import com.qys.livesMall.shop.modal.dto.shop.order.AddOrder;
import com.qys.livesMall.shop.modal.dto.shop.order.DirectAddOrder;
import com.qys.livesMall.shop.modal.entity.*;
import com.qys.livesMall.shop.modal.query.QueryOrder;
import com.qys.livesMall.shop.modal.query.QueryShopOrderListDto;
import com.qys.livesMall.shop.modal.vo.PayCostDetailVO;
import com.qys.livesMall.shop.modal.vo.PayCostVO;
import com.qys.livesMall.shop.modal.vo.ShopOrderDetailVO;
import com.qys.livesMall.shop.modal.vo.ShopOrderVo;
import com.qys.livesMall.shop.service.*;
import com.qys.livesMall.shop.service.api.impl.ShopOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 订单
 * </p>
 *
 * @author gmx
 * @since 2023-06-19
 */
@RestController
@RequestMapping("/app/shopOrderInfo")
@Tag(name="app-用户订单",description="app-用户订单")
public class AppShopOrderInfoController {
    @Resource
    private ShopOrderInfoService orderInfoService;
    @Resource
    private ShopOrderInfoMapper infoMapper;
    @Resource
    private ShopOrderSkuService orderSkuService;
    @Resource
    private ShopGoodsInfoService goodsInfoService;
    @Resource
    private ShopGoodsSkuService goodsSkuService;
    @Resource
    private IH2AppUserService appUserService;
    @Resource
    private H2ShopBaseDao h2ShopBaseDao;
    @Resource
    private ShopOrderInfoMapper orderInfoMapper;
    @Resource
    private ShopOrderCommentService orderCommentService;
    @Resource
    private ShopOrderService shopOrderService;
    @Resource
    private IH2AppUserAddressService appUserAddressService;

    @Autowired
    private MessageServer messageServer;

    @Resource
    private H2ProductSkuAttributeService attributeService;

    @Autowired
    private ShopOrderStatusManager shopOrderStatusManager;

    @Autowired
    private ShopOrderReturnApprovedService shopOrderReturnApprovedService;

    @Autowired
    private ShopOrderReturnExpressService expressService;

    @Autowired
    private FinanceShopAccountService financeShopAccountService;
    @Resource
    private PushUserDeviceService pushUserDeviceService;
    @Resource
    private ShopOrderMessageService shopOrderMessageService;

    @Operation(summary = "店铺查看订单")
    @PostMapping("/shopList")
    public R<Page<ShopOrderDto>> shopOrderList(@RequestBody QueryShopOrderDto orderDto){
        Page<ShopOrderDto> page = Page.of(orderDto.getCurrent(),orderDto.getSize());
        H2ShopBase shop = h2ShopBaseDao.getByUserId(SecurityUtils.getUserId());
        orderDto.setShopId(shop.getId().toString());
        return R.ok(infoMapper.queryOrderInfo(page,orderDto));
    }
    @PostMapping("/listInvoice")
    @Operation(summary = "订单发票列表")
    public R<Page<ShopOrderListDto>> listInvoice(@RequestBody QueryShopOrderListDto query){
        Page<ShopOrderListDto> page = Page.of(query.getCurrent(),query.getSize());
        Page<ShopOrderListDto> list = orderInfoMapper.queryShopInfoId(page, query);
        if(ObjectUtils.isEmpty(list.getRecords())){
          return R.ok(list);
        }
        list.getRecords().stream().forEach(e->{
            List<ShopOrderSku> sku = orderSkuService.getByOrderIdAndShop(query.getShopId(),e.getId());
            e.setOrderSkus(sku);
        });
        return R.ok(list);
    }
    @Operation(summary = "店铺查看订单详情")
    @GetMapping("/shopOrder/{orderId}")
    public R<ShopOrder> getshopOrder(@PathVariable Long orderId){
        ShopOrderInfo orderInfo = orderInfoService.getById(orderId);
        if (orderInfo.getIsDelete().equals("1")){
            return R.fail(MessageUtils.message("shop.not.find.order"));
        }
        H2ShopBase shop = h2ShopBaseDao.getByUserId(SecurityUtils.getUserId());
        if (ObjectUtils.isEmpty(orderInfo))return R.fail(MessageUtils.message("shop.not.find.order"));
        LambdaQueryWrapper<ShopOrderSku> orderSkuLambdaQueryWrapper= new LambdaQueryWrapper<>();
        orderSkuLambdaQueryWrapper.eq(ShopOrderSku::getOrderId,orderId);
        orderSkuLambdaQueryWrapper.eq(ShopOrderSku::getShopId,shop.getId());
        List<ShopOrderSku> orderSkus = orderSkuService.list(orderSkuLambdaQueryWrapper);
        if (orderSkus.size()==0)return R.fail(MessageUtils.message("shop.not.find.order"));
        ShopOrder shopOrder = new ShopOrder();
        shopOrder.setOrderInfo(orderInfo);
        shopOrder.setOrderSkus(orderSkus);
        return R.ok(shopOrder);
    }

    @PostMapping("/modifyAddress")
    @Operation(summary = "修改订单地址")
    public R<?> modifyAddress(@RequestBody ModifyOrderAddressDTO dto){
        H2AppUserAddress address = appUserAddressService.getById(dto.getAddressId());
        if(address == null){
            return R.fail("addressId error");
        }
        ShopOrderInfo shopOrderInfo = new ShopOrderInfo();
        shopOrderInfo.setId(dto.getOrderId());
        shopOrderInfo.setCountry(address.getCountry());
        shopOrderInfo.setCountryName(address.getCountryName());
        shopOrderInfo.setConsigUser(address.getUserName());
        shopOrderInfo.setPostalCode(address.getPostalCode());
        shopOrderInfo.setEmail(address.getEmail());
        shopOrderInfo.setAddress(address.getAddress());
        shopOrderInfo.setMobile(address.getMobile());
        shopOrderInfo.setCity(address.getCity());
        shopOrderInfo.setLandmark(address.getLandmark());
        orderInfoService.updateById(shopOrderInfo);
        return R.ok();
    }

    @PostMapping("/pay")
    public R payment(@RequestBody PayDto operationDto){

        Long userId = SecurityUtils.getUserId();
        H2AppUser user = appUserService.getById(userId);
        String oldPassword = user.getUserWithdrawalPassword();
        String newPassword = PasswordUtil.encrypt(operationDto.getPassword(), user.getUserName(), user.getSalt());
        if(!Objects.equals(newPassword, oldPassword)){
            return R.fail(MessageUtils.message("payment.failed.password"));
        }
       return shopOrderService.pay(operationDto.getOrderId());
    }

    /**
     * 通过购物车下单
     * @param addOrder
     * @return
     */
    @PostMapping("/add")
    public R<ShopOrder> add(@RequestBody AddOrder addOrder){

        try {
            H2AppUser appUser = appUserService.getById(SecurityUtils.getUserId());
            addOrder.setUserId(SecurityUtils.getUserId());
            addOrder.setUserName(appUser.getUserName());
            return R.ok(shopOrderService.add(addOrder));
        }catch (QysException e){
            return R.fail(e.getMessage());
        }

    }
    @PostMapping("/addone")
    public R<ShopOrder> add(@RequestBody DirectAddOrder addOrder){
        try {
            H2AppUser appUser = appUserService.getById(SecurityUtils.getUserId());
            addOrder.setUserId(SecurityUtils.getUserId());
            addOrder.setUserName(appUser.getUserName());
            return R.ok(shopOrderService.add(addOrder));
        }catch (QysException e){
            return R.fail(e.getMessage());
        }

    }

    @PostMapping("/cancel")
    public R cancel(@RequestBody ShopOrderIdea orderIdea){
        try {
            orderInfoService.cancel(orderIdea);
        }catch (QysException e){
            return R.fail(e.getMessage());
        }
        return R.ok();
    }
    @PostMapping("/delete")
    public R delete(@RequestBody ShopOrderIdea orderIdea){
        try {
            orderInfoService.delete(orderIdea);
        }catch (QysException e){
            return R.fail(e.getMessage());
        }
        return R.ok();
    }
    @GetMapping("/{orderId}")
    public R<ShopOrder> get(@PathVariable Long orderId){
        ShopOrderInfo orderInfo = orderInfoService.getById(orderId);
        if (orderInfo.getIsDelete().equals("1")){
            return R.fail(MessageUtils.message("shop.not.find.order"));
        }
        if (ObjectUtils.isEmpty(orderInfo))return R.fail(MessageUtils.message("shop.not.find.order"));
        LambdaQueryWrapper<ShopOrderSku> orderSkuLambdaQueryWrapper= new LambdaQueryWrapper<>();
        orderSkuLambdaQueryWrapper.eq(ShopOrderSku::getOrderId,orderId);
        List<ShopOrderSku> orderSkus = orderSkuService.list(orderSkuLambdaQueryWrapper);
        List<Long> skuIds = orderSkus.stream().map(ShopOrderSku::getSkuId).collect(Collectors.toList());
        Map<Long, ShopGoodsSku> goodsSkuMap = goodsSkuService.listByIds(skuIds).stream().collect(Collectors.toMap(ShopGoodsSku::getId, v -> v, (v1, v2) -> v1));
        orderSkus.stream().forEach(o->{
            o.setSkuAttr(attributeService.getSkuName(goodsSkuMap.get(o.getSkuId()).getSkuAttr()));
            ShopGoodsSku sku = goodsSkuService.getById(o.getSkuId());
            o.setShopGoodsId(sku.getShopGoodsId());
            o.setReturnInfo(shopOrderReturnApprovedService.getByOrderSkuId(o.getId()));
            if (o.getReturnInfo()!=null){
                o.setUserReturnExpress(expressService.getExpress(o.getReturnInfo().getId(),2));
                o.setPlatformReturnExpress(expressService.getExpress(o.getReturnInfo().getId(),1));
            }

        });
        if (orderSkus.size()==0)return R.fail(MessageUtils.message("shop.not.find.order"));
        ShopOrder shopOrder = new ShopOrder();
        shopOrder.setOrderInfo(orderInfo);
        Map<Long,List<ShopOrderSku>>skuMap= orderSkus.stream().collect(Collectors.groupingBy(ShopOrderSku::getShopId));
        List<ShopOrderDetailVO> detailVOS=new ArrayList<>();
        for (Long shopId:skuMap.keySet()){
            ShopOrderDetailVO detailVO=new ShopOrderDetailVO();
            detailVO.setShopName(skuMap.get(shopId).get(0).getShopName());
            detailVO.setOrderSkus( BeanProUtils.copyListProperties(skuMap.get(shopId), ShopOrderSkuDto::new));
            detailVOS.add(detailVO);
        }
        shopOrder.setOrderDetails(detailVOS);
        shopOrder.setOrderSkus(orderSkus);
        return R.ok(shopOrder);
    }

    /**
     * 订单列表
     * @param queryOrder
     * @return
     */
    @PostMapping("/list")
    public R<Page<ShopOrderVo>> list(@RequestBody QueryOrder queryOrder){
        List<Long> orderIdList=null;
        Page<ShopOrderInfo> orderInfo =new Page<>();
        Page<ShopOrderVo> orders =new Page<>();
        List<Integer> orderSkuStatuses=new ArrayList<>();
        List<Integer> orderStatuses=new ArrayList<>();
        if (queryOrder.getStatus()==null){
            //查全部
            queryOrder.setOrderStatus(null);
            queryOrder.setPayStatus(null);
        }else if (queryOrder.getStatus()==-1){
            //已取消
            orderSkuStatuses.add(OrderStatus.CANCELED);
        }else if(queryOrder.getStatus() ==0){
            //待付款
            queryOrder.setPayStatus(PayStatus.NONPAYMENT);
            orderSkuStatuses.add(OrderStatus.WAIT_PAY);
        }else if (queryOrder.getStatus()==1){
            queryOrder.setOrderStatus(OrderStatus.UNSHIPPED);
        }else if(queryOrder.getStatus()==2){
            queryOrder.setOrderStatus(OrderStatus.SHIPPED);
        }else if(queryOrder.getStatus()==3){
            orderStatuses.add(OrderStatus.RECEIVED);
            orderStatuses.add(OrderStatus.RETURNED);
            orderSkuStatuses.add(OrderStatus.RECEIVED);
            orderSkuStatuses.add(OrderStatus.RETURNED);
        }else if(queryOrder.getStatus()==4){
            orderSkuStatuses.add(OrderStatus.RETURN_APPLIED);
            orderSkuStatuses.add(OrderStatus.RETURN_CONFIRMED);
            orderSkuStatuses.add(OrderStatus.RETURNED);
        }
        queryOrder.setOrderStatuses(orderStatuses);
        queryOrder.setOrderSkuStatus(orderSkuStatuses);
        queryOrder.setUserId(SecurityUtils.getUserId());
        Page<ShopOrderDto> skuPage = Page.of(queryOrder.getCurrent(), queryOrder.getSize());
        orderInfo = orderInfoMapper.queryOrderList(skuPage, queryOrder);
        if (ObjectUtils.isEmpty(orderInfo.getRecords())){
            return R.ok(orders);
        }
        BeanUtil.copyProperties(orderInfo,orders);

        orders.setRecords(new ArrayList<ShopOrderVo>());
        for (ShopOrderInfo record : orderInfo.getRecords()) {
            ShopOrderVo order = new ShopOrderVo();
            order.setOrderInfo(record);
            List<ShopOrderSkuDto> skuDtos = new ArrayList<>();
            LambdaQueryWrapper<ShopOrderSku> orderSkuWrapper = new LambdaQueryWrapper<>();
            orderSkuWrapper.eq(ShopOrderSku::getOrderId,record.getId());
            List<ShopOrderSku> skus = orderSkuService.list(orderSkuWrapper);
            for (ShopOrderSku shopOrderSku : skus) {
                ShopOrderSkuDto skuDto = new ShopOrderSkuDto();
                ShopGoodsSku sku = goodsSkuService.getById(shopOrderSku.getSkuId());
                ShopGoodsInfo goods = goodsInfoService.getById(sku.getShopGoodsId());
                BeanUtil.copyProperties(shopOrderSku,skuDto);
                skuDto.setGoodsDesc(goods.getGoodsDesc());
                skuDto.setShopGoodsId(goods.getId());
                List<ShopOrderComment> commentList = orderCommentService.queryComment(skuDto.getId());
                if(ObjectUtils.isNotEmpty(commentList)){
                    order.setComment(true);
                }else {
                    order.setComment(false);
                }
                //获取售后记录
                skuDto.setReturnInfo(shopOrderReturnApprovedService.getByOrderSkuId(shopOrderSku.getId()));
                skuDtos.add(skuDto);
            }
//            Map<Long,List<ShopOrderSkuDto>>skuMap= skuDtos.stream().collect(Collectors.groupingBy(ShopOrderSku::getShopId));
//            List<ShopOrderDetailVO> detailVOS=new ArrayList<>();
//            for (Long shopId:skuMap.keySet()){
//                ShopOrderDetailVO detailVO=new ShopOrderDetailVO();
//                detailVO.setShopName(skuMap.get(shopId).get(0).getShopName());
//                detailVO.setOrderSkus(skuMap.get(shopId));
//                detailVOS.add(detailVO);
//            }
//            order.setOrderDetails(detailVOS);
            order.setOrderSkus(skuDtos);
            orders.getRecords().add(order);
        }

        return R.ok(orders);
    }

    /**
     * 发货
     * @param expressDto
     * @return
     */
    @PostMapping("/shipped")
    @Transactional(rollbackFor = {Exception.class})
    public R shipped(@RequestBody ShopOrderExpressDto expressDto){
        H2ShopBase shop=h2ShopBaseDao.getByUserId(SecurityUtils.getUserId());
        long now = System.currentTimeMillis();
        if (CollectionUtils.isEmpty(expressDto.getOrderIds())){
            return messageServer.failMsg(ExceptionEnum.PARAM_IS_ERROR);
        }
        for (Long orderId:expressDto.getOrderIds()) {
            List<ShopOrderSku> orderSkus = orderSkuService.getByOrderIdAndShop(shop.getId(),orderId);
            if(CollectionUtils.isEmpty(orderSkus)){
                continue;
            }
            for(ShopOrderSku orderSku:orderSkus) {
                if (Objects.equals(orderSku.getOrderStatus(), OrderStatus.SHIPPED)){
                    continue;
                }
                if (!Objects.equals(orderSku.getOrderStatus(), OrderStatus.UNSHIPPED)) {
                    continue;
                }
                if (Objects.equals(orderSku.getCostPay(), Constants.YesNoInt.NO)){
                    throw new QysException(ShopMessageEnum.SHOP_ORDER_NO_PAYMENT_FOR_GOODS);
                }
                orderSku.setConsignTime(now);
                orderSku.setOrderStatus(OrderStatus.SHIPPED);
                if (!orderSkuService.updateById(orderSku))
                    throw new QysException(MessageUtils.message("system.error.order"));
            }
            try {
                ShopOrderInfo orderInfo = orderInfoService.getById(orderId);
                List<ShopOrderSku> allOrderSkus = orderSkuService.getStatusByOrderId(orderInfo.getId());
                orderInfo.setOrderStatus(shopOrderStatusManager.getMainOrderStatus(allOrderSkus));
                orderInfo.setConsignTime(now);
                if (!orderInfoService.updateById(orderInfo)){
                    throw new QysException(MessageUtils.message("system.error.order"));
                }else {
                    //订单发货消息推送
                    if (orderInfo.getOrderStatus().intValue() == OrderStatus.RETURN_APPLIED.intValue()){
                        ShopOrderMessage orderMessage = new ShopOrderMessage();
                        orderMessage.setName("订单发货消息");
                        orderMessage.setBelong(ShopOrderMessageConstants.DELIVERGOODS);
                        orderMessage.setMessageType(ShopOrderMessageConstants.MESSAGETYPE);
                        orderMessage.setMessageUserId(orderInfo.getUserId());
                        H2AppUser h2AppUser=appUserService.getById(orderInfo.getUserId());
                        orderMessage.setMessageUserName(h2AppUser.getNickName());
                        orderMessage.setStatus(true);
                        orderMessage.setOrderId(orderInfo.getId());
                        orderMessage.setCreateTime(now);
                        orderMessage.setUpdateTime(now);
                        shopOrderMessageService.save(orderMessage);
                        PushUserDeviceDTO pushUserDeviceDTO = new PushUserDeviceDTO();
                        pushUserDeviceDTO.setUserIds(Arrays.asList(orderInfo.getUserId()));
                        PushTitleDTO pushTitleDTO=new PushTitleDTO();
                        pushTitleDTO.setChinese("订单已经发货了,订单编号:"+orderInfo);
                        pushTitleDTO.setEnglish("The order has been shipped, order number:"+orderInfo);
                        pushUserDeviceDTO.setTitle(pushTitleDTO);
                        PushUserDeviceContentDTO content =new PushUserDeviceContentDTO();
                        content.setType(PushMessageTypeEnum.ORDER_PUSH);
                        JSONObject json = new JSONObject();
                        json.putOnce("chinese","订单已经发货了,订单编号:"+orderInfo);
                        json.putOnce("english","The order has been shipped, order number:"+orderInfo);
                        content.setData(json.toString());
                        pushUserDeviceDTO.setContent(content);
                        pushUserDeviceService.pushUserDevice(pushUserDeviceDTO);
                    }
                }

            } catch (QysException e) {
                R.fail(e.getMessage());
            }
        }
        return R.ok();
    }

    @Operation(summary = "确认收货")
    @PostMapping("/operation")
    public R userOperation(@RequestBody OperationDto operationDto){
        Long userId = SecurityUtils.getUserId();
        H2AppUser user = appUserService.getById(userId);
        String oldPassword = user.getUserWithdrawalPassword();
        String newPassword = PasswordUtil.encrypt(operationDto.getPassword(), user.getUserName(), user.getSalt());
        if(!Objects.equals(newPassword, oldPassword)){
            return R.fail(MessageUtils.message("payment.failed.password"));
        }
        try {
            return orderInfoService.operation(operationDto.getOrderSkuId());
        }catch (QysException e){
            return R.fail(e.getMessage());
        }

    }

    /**
     * 需缴纳成本
     * @param expressDto
     * @return
     */
    @PostMapping("/getWaitPayCost")
    public R getWaitPayCost(@RequestBody ShopOrderExpressDto expressDto){
        H2ShopBase shop=h2ShopBaseDao.getByUserId(SecurityUtils.getUserId());
        long now = System.currentTimeMillis();
        if (CollectionUtils.isEmpty(expressDto.getOrderIds())){
            return messageServer.failMsg(ExceptionEnum.PARAM_IS_ERROR);
        }
        BigDecimal totalCost=BigDecimal.ZERO;
        List<ShopOrderInfo> infos= orderInfoService.listByIds(expressDto.getOrderIds());
        List<PayCostDetailVO> details=new ArrayList<>();
        for (ShopOrderInfo order:infos) {
            List<ShopOrderSku> orderSkus = orderSkuService.getByOrderIdAndShop(shop.getId(),order.getId());
            if(CollectionUtils.isEmpty(orderSkus)){
                continue;
            }
            BigDecimal cost=BigDecimal.ZERO;
            PayCostDetailVO detail=new PayCostDetailVO();
            for(ShopOrderSku orderSku:orderSkus) {
                if (Objects.equals(orderSku.getCostPay(), Constants.YesNoInt.NO)) {
                    cost = cost.add(orderSku.getCostPrice().multiply(new BigDecimal(orderSku.getNum())));
                }
            }
            detail.setCost(cost);
            detail.setOrderNo(order.getOrderNo());
            details.add(detail);
            totalCost=totalCost.add(cost);
        }
        FinanceShopAccount account= financeShopAccountService.liatByShopIds(Arrays.asList(shop.getId())).get(0);
        PayCostVO vo=new PayCostVO();
        vo.setCost(totalCost);
        vo.setShopBalance(account.getAvailableBalance());
        vo.setDetails(details);
        return R.ok(vo);
    }

    /**
     * 缴纳成本
     * @param expressDto
     * @return
     */
    @PostMapping("/payCost")
    @Transactional(rollbackFor = {Exception.class})
    public R payCost(@RequestBody ShopOrderExpressDto expressDto){
        R r= orderSkuService.payCost(expressDto.getOrderIds());
        if (r.getSuccess()){
            return shipped(expressDto);
        }
        return r;
    }
}
